package com.jy.wms.common.quartz;

import com.jy.wms.service.*;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.annotation.Resource;

@Configuration
public class SchedulerConfig {

    @Resource
    private WmsGoodsAlarmService ws;

    /*@Resource
    private WmsProvinceRankingTimingService ProvinceRankingReportService;*/

    @Resource
    private WmsReportsService wmsReportsService;

    @Resource
    private WmsProductCategorysService wmsProductCategorysService;

    @Resource
    private WmsProductVelocityService wmsProductVelocityService;

    @Resource
    private WmsPickingService wmsPickingService;

    @Resource
    private WmsStoreHouseService WmsStoreHouseService;

    @Bean
    public SchedulerFactoryBean  getSchedulerFactoryBean() {
        return new SchedulerFactoryBean();
    }

    @Bean(name = "cronTrigger")
    public CronTrigger getTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 8 * * ?");
        return TriggerBuilder.newTrigger().withIdentity("wmsGoodsAlarmScheduledJobTrigger", "group1").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "jobDetail")
    public JobDetail getJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("wmsGoodsAlarmService", ws);
        return JobBuilder.newJob(wmsGoodsAlarmScheduledJob.class).setJobData(jb).withIdentity("wmsGoodsAlarmScheduledJob", "group1").build();
    }

    @Bean(name = "StockcronTrigger")
    public CronTrigger getStockTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 23 L * ?");
        return TriggerBuilder.newTrigger().withIdentity("WmsReportsAlarmScheduledJobTrigger", "group2").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "StockjobDetail")
    public JobDetail getStockJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("wmsReportsService", wmsReportsService);
        return JobBuilder.newJob(WmsReportsAlarmScheduledJob.class).setJobData(jb).withIdentity("WmsReportsAlarmScheduledJob", "group2").build();
    }


    /*@Bean(name = "ProvinceTrigger")
    public CronTrigger ProvinceDirectSelling(){
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 22 * * ?");
        return TriggerBuilder.newTrigger().withIdentity("WmsProvinceRankingReportJobTrigger", "group3").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "JobDetail")
    public JobDetail getProvince() {
        JobDataMap jb = new JobDataMap();
        jb.put("ProvinceRankingReportService", ProvinceRankingReportService);
        ///ProvinceRankingReportService.ProvincialTimer();
        return JobBuilder.newJob(WmsProvinceAlarmScheduledJob.class).setJobData(jb).withIdentity("WmsProvinceRankingReportService", "group3").build();
    }*/

    @Bean(name = "ProductTrigger")
    public CronTrigger getProductTrigger(){
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 20 23 L * ?");
        return TriggerBuilder.newTrigger().withIdentity("WmsProductCategoryJobTrigger", "group4").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "ProductJobDetail")
    public JobDetail getProductJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("wmsProductCategorysService", wmsProductCategorysService);
        return JobBuilder.newJob(WmsProductCategoryJob.class).setJobData(jb).withIdentity("WmsProductCategorysService", "group4").build();
    }

    @Bean(name = "VelocityTrigger")
    public CronTrigger getVelocityTrigger(){
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 1 1 * ?");
        return TriggerBuilder.newTrigger().withIdentity("VelocityTrigger", "group5").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "VelocityJobDetail")
    public JobDetail getVelocityJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("wmsProductVelocityService", wmsProductVelocityService);
        return JobBuilder.newJob(WmsProductVelocityScheduledJob.class).setJobData(jb).withIdentity("WmsProductVelocityService", "group5").build();
    }
    @Bean(name = "PickTrigger")
    public CronTrigger getPickTrigger(){
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/10 * * * * ?");
        return TriggerBuilder.newTrigger().withIdentity("PickTrigger", "group6").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "PickJobDetail")
    public JobDetail getPickJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("wmsPickingService", wmsPickingService);
        return JobBuilder.newJob(WmsPickingVelocityScheduledJob.class).setJobData(jb).withIdentity("WmsProductVelocityService", "group6").build();
    }

    @Bean(name = "StoreHouseTrigger")
    public CronTrigger WmsStoreHouseTrigger(){
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 30 23 * * ?");
        return TriggerBuilder.newTrigger().withIdentity("StoreHouseTrigger", "group7").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "StoreHouseJobDetail")
    public JobDetail WmsStoreHouseJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("WmsStoreHouseService", WmsStoreHouseService);
        return JobBuilder.newJob(WmsStoreHouseScheduledJob.class).setJobData(jb).withIdentity("WmsStoreHouseService", "group7").build();
    }
}
